home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 385 / prg_3 / prg_3bp.s < prev    next >
Text File  |  1985-11-19  |  5KB  |  127 lines

  1.  ; Program Name: PRG_3BP.S
  2.  
  3.  ; Assembly Instructions:
  4.  
  5.  ;    Assemble in PC-relative mode and save with a TOS extension.
  6.  
  7.  ; Program Function:
  8.  
  9.  ;    Illustrates the use of GEMDOS function $4A to return to GEMDOS all
  10.  ; memory except that required by this program.
  11.  
  12.  ; Execution Instructions:
  13.  
  14.  ;    Double click on PRG_3BP.TOS from the desktop.  After viewing the
  15.  ; program's output, press the Return key to terminate execution.
  16.  
  17.  ; Because base page information is needed by this program, if it is to
  18.  ; be executed in the AssemPro debugger, it must be loaded with the
  19.  ; "Execute program" function.
  20.  
  21.  ; MAJOR NOTE:
  22.  
  23.  ;    Whenever a program which processes base page information is to be
  24.  ; executed in the AssemPro debugger, special attention must be paid to the
  25.  ; process by which the program is loaded into the debugger.
  26.  
  27.  ;    If the program is loaded into the debugger with the "Execute program"
  28.  ; function, the entire program can be executed.
  29.  
  30.  ;    If, however, the program is loaded into the debugger as a result of
  31.  ; just having been assembled, the instructions which process basepage
  32.  ; information cannot be executed because there is no basepage when a program
  33.  ; is loaded by that process.
  34.  
  35.  ;    For this particular program you would procede as follows: relocate the
  36.  ; program by clicking on the Relocate button, then execute one, and only
  37.  ; one, of the initialization instructions.  That is instruction four of the
  38.  ; program:
  39.  ;
  40.  ;             lea  stack, a7
  41.  
  42.  ;    To accomplish this, move the PC cursor in the disassembly output field
  43.  ; to the fourth instruction, and execute the instruction by single stepping.
  44.  ; Then, move the PC cursor to the line containing the label "mainline".
  45.  ; Now, execution may proceed via the "Run program" or "Single step" buttons.
  46.  
  47.  ;    A program that used a default stack provided by the system would
  48.  ; require only that the PC cursor be moved beyond the initialization
  49.  ; sequence, which includes the return_memory algorithm.
  50.  
  51. calculate_program_size:
  52.  lea        program_end, a0     ; Put "end of program" address in A0.
  53.  movea.l    4(a7), a1           ; Put basepage address in A1.
  54.  suba.l     a1, a0              ; Subtract basepage address from program's
  55.                                 ; ending address.
  56.  lea        stack, a7           ; Point A7 to this program's stack.
  57.  
  58. return_memory:                  ; Return unused memory to operating system.
  59.  move.l     a0, -(sp)           ; Store total program length in stack.
  60.  move.l     a1, -(sp)           ; Store basepage address in stack.
  61.  move.l     #$4A0000, -(sp)     ; Function = m_shrink = GEMDOS $4A0000.
  62.  trap       #1                  ; GEMDOS call.
  63.  lea        $C(a7), sp          ; Reset stack pointer to top of stack.
  64.  
  65.  ; Note: When the stack pointer must be moved 8 bytes or less, use 
  66.  ;       addq.l #n, sp, where n is the number of bytes.  When it must
  67.  ;       be moved more than 8 bytes, addq.l can't be used.
  68.  
  69.  ;       Although you may be tempted to use adda.l #n, sp in that case, a
  70.  ;       better choice is lea n(a7), sp because it is twice as fast and
  71.  ;       requires 2 bytes less of memory.  Program LEA_ADDA.TOS verifies
  72.  ;       these claims.
  73.  
  74. mainline:                       ; Marks the beginning of program proper.
  75.  lea        newline, a0
  76.  bsr.s      print_string
  77.  
  78.  ; The above instructions prevent damage to the debugger screen and skip a
  79.  ; line for printer output.  Skipping a line on the printer separates the
  80.  ; program output from a listing which precedes execution, or it will 
  81.  ; separate the results of repeated executions.
  82.  
  83. print_declared_string:
  84.  lea        string, a0          ; Put address of the label "string" in A0.
  85.  bsr.s      print_string
  86.  
  87. wait_for_keypress: 
  88.  move.w     #8, -(sp)           ; Function = c_necin = GEMDOS $8.
  89.  trap       #1                
  90.  addq.l     #2, sp            
  91.  
  92. terminate:
  93.  move.w    #0, -(sp)            ; Function = p_term_old = GEMDOS $0.
  94.  trap      #1                 
  95.  
  96.  ; SUBROUTINES
  97.  
  98. print_string:                   ; Expects address of string to be in A0.
  99.  pea        (a0)                ; Push address of string onto stack.
  100.  move.w     #9, -(sp)           ; Function = c_conws = GEMDOS $9.
  101.  trap       #1                
  102.  addq.l     #6, sp
  103.  rts
  104.  
  105.  data
  106. newline: dc.b $D,$A,0  ; All strings must be NULL terminated because the
  107.                        ; function we are using to print them requires it.
  108.  
  109.                        ; Note that the ASCII code for a NULL character is $0,
  110.                        ; which is equal to decimal 0.
  111.  
  112.                        ; The ASCII code for a carriage return is $D; that for
  113.                        ; a linefeed is $A.
  114.  
  115. string:  dc.b 'This string will not overwrite the AssemPro debugger screen.'
  116.          dc.b $D,$A,0  ; The string is continued on this line.  Here, we
  117.                        ; declare a carriage return, linefeed and terminate
  118.                        ; the entire string with a NULL = $0 = 0.
  119.  
  120.  bss
  121.  align                          ; Align storage on a word boundary.
  122.                  ds.l     16    ; Stack.
  123. stack:           ds.l      0    ; Address of stack.
  124. program_end:     ds.l      0    ; Marks the end of program memory.
  125.  end               
  126.  
  127.